﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using strange.extensions.context.api;
using strange.extensions.dispatcher.eventdispatcher.api;

public class ScoreService : ISomeService
{
    [Inject]//自动注入
    public IEventDispatcher dispatcher     // A Dispatcher that uses IEvent to send messages.dispatcher用时间来发消息
    {
        get;set;
    }
    [Inject(ContextKeys.CONTEXT_VIEW)]//在任何一个地方都能得到挂在了ContextView的物体
    public GameObject ContextView { get; set; }
    public string URL
    {
        get;set;
    }

    public void Request()
    {
        //等待一秒
        MonoBehaviour root = ContextView.GetComponent<GameRoot>();
        root.StartCoroutine(GetScore());
    }
    private IEnumerator GetScore()
    {
        yield return new WaitForSeconds(1f);
        int score = Random.Range(0, 20);
        Debug.Log("已获得服务器数据：" + score);
        dispatcher.Dispatch(Events.REQUEST_COMPLETE, score);//根据事件发消息
    }
}
